﻿using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Transformable_Engine_v2.Engine.Graphics
{
    public class Vertex
    {
        /// <summary>
        /// Color of the Vertex
        /// </summary>
        public Color Color { get; set; }

        /// <summary>
        /// Position of the Vertex
        /// </summary>
        public TE_Vector2 Position { get; set; }

        /// <summary>
        /// Absolute position of the vertex
        /// </summary>
        public TE_Vector2 AbsolutePosition { get; private set; }

        public void SetAbsolutePosition(TE_Vector2 parentPosition)
        {
            AbsolutePosition = Position + parentPosition;
        }

        /// <summary>
        /// Creates a new instance of the Vertex class
        /// </summary>
        public Vertex()
            : this(TE_Vector2.Zero, Color.Black)
        {
        }

        /// <summary>
        /// Creates a mew instance of the Vertex class
        /// </summary>
        /// <param name="position">Position of the vertex</param>
        /// <param name="color">Color of the vertex</param>
        public Vertex(TE_Vector2 position, Color color)
        {
            Color = color;
            Position = position.ToGridbound();
            AbsolutePosition = TE_Vector2.Zero;
        }

        /// <summary>
        /// Creates a new instance of the Vertex class
        /// </summary>
        /// <param name="x">Position of the vertex</param>
        /// <param name="y">Position of the vertex</param>
        /// <param name="color">Color of the Vertex</param>
        public Vertex(float x, float y, Color color)
            : this(new TE_Vector2(x, y), color)
        {
        }

        public SFML.Graphics.Vertex ToSFMLVertex()
        {
            return new SFML.Graphics.Vertex(AbsolutePosition.ToVector2f(), Color.ToSFMLColor());
        }
    }
}